package com.ham.mud.commands;

import com.ham.mud.Colors;
import com.ham.mud.Runner;
import com.ham.mud.ServerConnection;
import com.ham.mud.characters.player.Player;

import java.util.List;

/**
 * Created by hlucas on Jun 30, 2011 at 2:48:54 PM
 */
public class GossipCommand extends PlayerCommand {
    @Override
    public void execute(ServerConnection connection, String[] params) {
        if(params.length == 0) {
            connection.printSolo("Gossip what?");
            return;
        }
        
        StringBuilder sb = new StringBuilder();
        for(String param : params) {
            sb.append(param);
            sb.append(" ");
        }

        String playersName = connection.getPlayer().getName();

        List<ServerConnection> serverConnectionList = Runner.STATIC_INSTANCE.getConnections();
        for(ServerConnection serverConnection : serverConnectionList) {
            Player otherPlayer = serverConnection.getPlayer();
            if(otherPlayer != null && otherPlayer.getName().equals(playersName)) {
                serverConnection.printSolo("{wYou gossip, {W\"{g" + sb.toString().trim() + "{W\"");
            } else {
                serverConnection.printSolo(Colors.NEW_LINE + "{w" + playersName + " gossips, {W\"{g" + sb.toString().trim() + "{W\"");
            }
        }
    }

    @Override
    protected String getCommandName() {
        return "gossip";
    }
}
